package com.ruoyi.zhgd.controller;

import java.util.List;
import java.util.Arrays;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.hutool.core.lang.tree.Tree;
import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.zhgd.domain.ZjNWarningUsing;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;

import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.zhgd.domain.vo.ZjNWarningUsingVo;
import com.ruoyi.zhgd.domain.bo.ZjNWarningUsingBo;
import com.ruoyi.zhgd.service.IZjNWarningUsingService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 报警通知短信发送是否启用信息
 *
 * @author tll
 * @date 2023-11-16
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/zhgd/nWarningUsing")
public class ZjNWarningUsingController extends BaseController {

    private final IZjNWarningUsingService iZjNWarningUsingService;

    /**
     * 查询报警通知短信发送是否启用信息列表
     */
    @SaCheckLogin
    @GetMapping("/list")
    public R<ZjNWarningUsing> list() {
        return R.ok(iZjNWarningUsingService.queryPageList());
    }

    @SaCheckLogin
    @GetMapping("/page")
    public TableDataInfo<ZjNWarningUsingVo> page(PageQuery pageQuery, ZjNWarningUsingBo bo) {
        return iZjNWarningUsingService.page(pageQuery, bo);
    }

    /**
     * 导出报警通知短信发送是否启用信息列表
     */
    @SaCheckLogin
    @Log(title = "报警通知短信发送是否启用信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ZjNWarningUsingBo bo, HttpServletResponse response) {
        List<ZjNWarningUsingVo> list = iZjNWarningUsingService.queryList(bo);
        ExcelUtil.exportExcel(list, "报警通知短信发送是否启用信息", ZjNWarningUsingVo.class, response);
    }

    /**
     * 获取报警通知短信发送是否启用信息详细信息
     *
     * @param id 主键
     */
    @SaCheckLogin
    @GetMapping("/{id}")
    public R<ZjNWarningUsingVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable String id) {
        return R.ok(iZjNWarningUsingService.queryById(id));
    }

    /**
     * 新增报警通知短信发送是否启用信息
     */
    @SaCheckLogin
    @Log(title = "报警通知短信发送是否启用信息", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ZjNWarningUsingBo bo) {
        return toAjax(iZjNWarningUsingService.insertByBo(bo));
    }

    /**
     * 修改报警通知短信发送是否启用信息
     */
    @SaCheckLogin
    @Log(title = "报警通知短信发送是否启用信息", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ZjNWarningUsingBo bo) {
        return toAjax(iZjNWarningUsingService.updateByBo(bo));
    }

    /**
     * 删除报警通知短信发送是否启用信息
     *
     * @param ids 主键串
     */
    @SaCheckLogin
    @Log(title = "报警通知短信发送是否启用信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable String[] ids) {
        return toAjax(iZjNWarningUsingService.deleteWithValidByIds(Arrays.asList(ids), true));
    }

    /**
     * 发送短信通知
     * @param receiveAddr 收件人手机号数组
     * @param content 短信内容
     */
    @SaCheckLogin
    @PostMapping("/send")
    public int send(@NotNull(message = "收件人不能为空") @PathVariable List<String> receiveAddr,
                     @NotNull(message = "短信内容不能为空") @PathVariable String content) {
        return iZjNWarningUsingService.send(receiveAddr, content);
    }

    /**
     * 获取部门树列表 业务页面左侧结构树 第一层
     */
    @SaCheckLogin
    @GetMapping("/businessDeptTreeTop")
    public R<List<Tree<Long>>> businessDeptTreeTop(SysDept dept) {
        return R.ok(iZjNWarningUsingService.businessDeptTreeTop(dept));
    }

}
